package leetcode;

import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:160. 相交链表
 * User: 东莞呵呵
 * Date:2022-07-10
 * Time:21:12
 */
public class TestDemo4 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashSet<ListNode> set=new HashSet<>();
        while(headA!=null){
            set.add(headA);
            headA=headA.next;
        }
        while(headB!=null){
            if(set.contains(headB)){
                return headB;
            }
            headB=headB.next;
        }
        return null;
    }
}
